package com.soft.javase.day02.practice.order;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/16
 */
// 用户类
class User {
    private String name;
    private String address;
    private String phone;
    private Order[] orders;
    private int orderCount;

    public User(String name, String address, String phone, int maxOrders) {
        this.name = name;
        this.address = address;
        this.phone = phone;
        this.orders = new Order[maxOrders];
        this.orderCount = 0;
    }

    // 下单
    public void placeOrder(long orderId, Goods[] goods) {
        if (orderCount < orders.length) {
            Order newOrder = new Order(orderId, this, goods.length);
            for (Goods g : goods) {
                newOrder.addGoods(g);
            }
            orders[orderCount] = newOrder;
            orderCount++;
            System.out.println(name + " 下单成功，订单号: " + orderId);
        } else {
            System.out.println("用户订单数量已达上限，无法创建新订单！");
        }
    }

    public String getName() { return name; }
    public Order[] getOrders() { return orders; }
    public int getOrderCount() { return orderCount; }
}